home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14443 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: wkaufman.us.oracle.com!wkaufman
  2. From: wkaufman@wkaufman.us.oracle.com (William Kaufman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: "Overlapping Objects"
  5. Date: 14 Apr 1996 23:10:48 GMT
  6. Organization: Oracle Corporation, Redwood Shores CA
  7. Message-ID: <4ks0lo$b1n@inet-nntp-gw-1.us.oracle.com>
  8. References: <31714280.201A@micromedia.on.ca>
  9. NNTP-Posting-Host: wkaufman.us.oracle.com
  10.  
  11. In article <31714280.201A@micromedia.on.ca> Richard Steadman <rsteadma@micromedia.on.ca> writes:
  12. ] Hello.
  13. ] I have a question which is quite simple, but I can't seem to find
  14. ] the right answer anywhere.
  15. ] I'm trying to figure out when it is necessary to use the memmove()
  16. ] function when copying strings. K&R and the man page says to use it
  17. ] when the "objects overlap". But I can't find a formal definition
  18. ] for this phrase (it's not in the FAQ either -- I checked!).
  19.  
  20.     If you've got two pointers into the same piece of memory, they
  21. overlap if either pointer is in the middle of the other's region (i.e.,
  22. between the other pointer and that pointer plus the size you're
  23. copying).
  24.  
  25. ] Here's the scenario: I have a string, and want to copy the tail of
  26. ] it to an earlier part of the string. The two pieces are *not* 
  27. ] overlappng when the function is called, but they may be when the 
  28. ] copy is finished.
  29. ] Given this, it safe to use strcat() instead of memmove()?
  30.  
  31.     I'm not sure I understand--they either overlap or they don't, and
  32. asking _at what time_ fixed chunks of memory overlap doesn't make sense
  33. to me.  But I think your answer is "No".
  34.  
  35.                                            -- Bill K.
  36.  
  37. Bill Kaufman             | "I mean ... it's not even been a two-and-two-make-
  38. wkaufman@us.oracle.com   |  five sort of day, it's more like a two-and-two-
  39.                          |  make ... *fish* ..."  -- "Cages", Dave McKean
  40.